//
//  BMHPromptView.m
//  BMHVideoMain
//
//  Created by 陈宪栋 on 2017/4/19.
//  Copyright © 2017年 Maoyx. All rights reserved.
//

#import "BMHPromptView.h"
#import <UIImage+Resize.h>
#import <ReactiveCocoa.h>


@interface BMHPromptView ()
@property(nonatomic,strong) UIImageView *imageView;
@property(nonatomic,strong) UILabel *titleLabel;
@property(nonatomic,strong) UILabel *secondtitleLabel;

@end

@implementation BMHPromptView

-(instancetype)initWithImage:(UIImage *)image {
    self = [super init];
    if (self) {
        self.imageView = [[UIImageView alloc]initWithImage:image];
        [self addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.and.top.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(88, 88));
        }];
        
//        self.titleLabel = [[UILabel alloc] init];
//        self.titleLabel.text = @"数据加载失败\n请确保手机已连接到网络";
//        self.titleLabel.numberOfLines = 2;
//        self.titleLabel.font = [UIFont boldSystemFontOfSize:14];
//        self.titleLabel.textColor = RGB(140, 140, 140);
//        self.titleLabel.textAlignment = NSTextAlignmentCenter;
//        [self addSubview:self.titleLabel];
//        CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(200, 40)];
//        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.imageView.mas_bottom).offset(10);
//            make.centerX.equalTo(self);
//            make.size.mas_equalTo(size);
//        }];
        
        self.reTryButton = [[UIButton alloc] init];
        [self.reTryButton setTitleColor:kLightGrayColor forState:UIControlStateNormal];
        self.reTryButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [self addSubview:self.reTryButton];
        [self.reTryButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageView.mas_bottom).offset(10);
            make.width.equalTo(@(210));
            make.height.equalTo(@(36));
            make.centerX.equalTo(self.imageView);
        }];
        
        @weakify(self);
        self.reTryButton.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
            @strongify(self);
            if (self.touchBlock) {
                self.touchBlock();
            }
            return [RACSignal empty];
        }];
    }
    return self;
}

- (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image {
    self = [super init];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithImage:image];
        [self addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.and.top.equalTo(self);
            make.size.mas_equalTo(self.imageView.frame.size);
        }];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.text = title;
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        self.titleLabel.textColor = HEXCOLOR(0x9c9c9c);
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLabel];
        CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(200, 40)];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageView.mas_bottom).offset(20);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(size);
        }];
    }
    return self;
}
- (instancetype)initWithFirstTitle:(NSString *)title secondTitle:(NSString *)secondTitle image:(UIImage *)image{
    self = [super init];
    if (self) {
        self.imageView = [[UIImageView alloc] initWithImage:image];
        [self addSubview:self.imageView];
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.and.top.equalTo(self);
            make.size.mas_equalTo(self.imageView.frame.size);
        }];
        
        self.titleLabel = [[UILabel alloc] init];
        self.titleLabel.text = title;
        self.titleLabel.font = [UIFont systemFontOfSize:16];
        self.titleLabel.textColor = HEXCOLOR(0x9c9c9c);
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.titleLabel];
        CGSize size = [self.titleLabel sizeThatFits:CGSizeMake(200, 40)];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.imageView.mas_bottom).offset(20);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(size);
        }];
        self.secondtitleLabel = [[UILabel alloc] init];
        self.secondtitleLabel.text = secondTitle;
        self.secondtitleLabel.font = [UIFont systemFontOfSize:16];
        self.secondtitleLabel.textColor = HEXCOLOR(0x9c9c9c);
        self.secondtitleLabel.textAlignment = NSTextAlignmentCenter;
        [self addSubview:self.secondtitleLabel];
        CGSize sizes = [self.secondtitleLabel sizeThatFits:CGSizeMake(200, 40)];
        [self.secondtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom).offset(5);
            make.centerX.equalTo(self);
            make.size.mas_equalTo(sizes);
        }];

        
        self.loginButton = [[UIButton alloc] init];
        self.loginButton.layer.cornerRadius = 17;
        self.loginButton.layer.masksToBounds = YES;
        [self.loginButton setTitle:@"登陆" forState:UIControlStateNormal];
        self.loginButton.titleLabel.font = [UIFont systemFontOfSize:16];
        [self.loginButton setBackgroundImage:[UIImage resizedImageWithName:@"conten_bj_zhuse_default"] forState:UIControlStateNormal];
        self.loginButton.userInteractionEnabled = YES;
        [self addSubview:self.loginButton];
        [self.loginButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.secondtitleLabel.mas_bottom).offset(15);
            make.width.equalTo(@(110));
            make.height.equalTo(@(34));
            make.centerX.equalTo(self.secondtitleLabel);
        }];
        [self.loginButton addTarget:self action:@selector(handlejjjjjj) forControlEvents:UIControlEventTouchUpInside];
        @weakify(self);
        
        self.loginButton.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
            @strongify(self);
            if (self.touchBlock) {
                self.touchBlock();
            }
            return [RACSignal empty];
        }];

    }
    return self;

}
- (void)handlejjjjjj{
    
}
@end
